// ====================================================================================
// RibbonTableItem.cs
//
// Created by: NI, 2007.03.27
// Revised by: NI, 2007.11.23
// ====================================================================================
using System;

namespace RibbonExplorer.Storage
{
  // ====================================================================================
  /// <summary>
  /// This class represents a ribbon control in the ribbon table.
  /// </summary>
  // ====================================================================================
  public class RibbonTableItem
  {
    #region Private fields

    private string _ControlId;
    private ControlType _Type;
    private string _TabSet;
    private string _Tab;
    private string _Group;
    private string _Parent;
    private int _Ordering;
    private int _PolicyId;

    #endregion

    #region Lifecycle methods

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Creates an item from a tab delimited string.
    /// </summary>
    /// <param name="text">Rext describing item properties.</param>
    // --------------------------------------------------------------------------------------------
    public RibbonTableItem(string text)
    {
      InitFromTabDelimitedText(text);
    }

    #endregion

    #region Public Properties

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Gets the ID of the control
    /// </summary>
    // --------------------------------------------------------------------------------------------
    public string ControlId
    {
      get { return _ControlId; }
    }

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Gets the type of the control
    /// </summary>
    // --------------------------------------------------------------------------------------------
    public ControlType Type
    {
      get { return _Type; }
    }

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Gets the ID of the tabset holding the control
    /// </summary>
    // --------------------------------------------------------------------------------------------
    public string TabSet
    {
      get { return _TabSet; }
    }

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Gets the ID of the tab holding the control
    /// </summary>
    // --------------------------------------------------------------------------------------------
    public string Tab
    {
      get { return _Tab; }
    }

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Gets the ID of the group holding the control
    /// </summary>
    // --------------------------------------------------------------------------------------------
    public string Group
    {
      get { return _Group; }
    }

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Gets the parent control item of this control
    /// </summary>
    // --------------------------------------------------------------------------------------------
    public string Parent
    {
      get { return _Parent; }
    }

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Gets the "Ordering" property of the control
    /// </summary>
    // --------------------------------------------------------------------------------------------
    public int Ordering
    {
      get { return _Ordering; }
    }

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Gets the "PolicyID" property of the control
    /// </summary>
    // --------------------------------------------------------------------------------------------
    public int PolicyId
    {
      get { return _PolicyId; }
    }

    #endregion

    #region Private methods

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Helpere method to convert the tab delimited text representation.
    /// </summary>
    /// <param name="text">Tab delimited text of control infromation</param>
    // --------------------------------------------------------------------------------------------
    private void InitFromTabDelimitedText(string text)
    {
      string[] fields = text.Split('\t');
      _ControlId = fields[0];

      switch(fields[1].ToLower().Trim())
      {
        case "button":
          _Type = ControlType.Button;
          break;
        case "button (dialogboxlauncher)":
          _Type = ControlType.DialogBoxLauncher;
          break;
        case "checkbox":
          _Type = ControlType.CheckBox;
          break;
        case "combobox":
          _Type = ControlType.ComboBox;
          break;
        case "control":
          _Type = ControlType.Control;
          break;
        case "dropdown":
          _Type = ControlType.DropDown;
          break;
        case "gallery":
          _Type = ControlType.Gallery;
          break;
        case "group":
          _Type = ControlType.Group;
          break;
        case "labelcontrol":
          _Type = ControlType.LabelControl;
          break;
        case "menu":
          _Type = ControlType.Menu;
          break;
        case "menuseparator":
          _Type = ControlType.MenuSeparator;
          break;
        case "splitbutton":
          _Type = ControlType.SplitButton;
          break;
        case "tab":
          _Type = ControlType.Tab;
          break;
        case "tabset":
          _Type = ControlType.TabSet;
          break;
        case "togglebutton":
          _Type = ControlType.ToggleButton;
          break;

        default:
          _Type = ControlType.None;
          break;
      }

      _TabSet = fields[2];
      _Tab = fields[3];
      _Group = fields[4];
      _Parent = fields[5];
      _Ordering = Int32.Parse(fields[8]);
      _PolicyId = Int32.Parse(fields[9]);
    }

    #endregion
  }
}
